package com.lanou.managerLogin.order.web.servlet;

import com.lanou.managerLogin.order.service.OrderService;
import com.lanou.managerLogin.order.domain.Order;
import com.lanou.managerLogin.order.domain.OrderItem;
import com.lanou.managerLogin.book.domain.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/orderListServlet")
public class OrderListServlet extends HttpServlet {

    private OrderService os = new OrderService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<Order> orderList = os.selectOrder();
        for (Order order : orderList) {
            List<OrderItem> orderItemList = os.selectOrderItem(order.getOid());
            for (OrderItem orderItem : orderItemList) {
                Book book = os.oneBook(orderItem.getBid());
                orderItem.setBook(book);
            }
            order.setOrderItemList(orderItemList);
        }
        req.setAttribute("orderList", orderList);
        req.getRequestDispatcher("/adminjsps/admin/order/list.jsp").forward(req, resp);
    }
}
